<cfcomponent
	displayname="User"
	output="false"
	hint="A bean which models the User.">

	<cfset variables.instance = StructNew() />

	<cffunction name="init" access="public" returntype="User" output="false">
		<cfargument name="userID" type="string" default="00000000-0000-0000-0000000000000000" />
		<cfargument name="role" type="string" default="0" />
		<cfargument name="roleCode" type="string" default="guest" />
		<cfargument name="timezone" type="string" default="America/New_York" />
		<cfargument name="defaultView" type="string" default="month" />
		<cfargument name="isLoggedIn" type="boolean" default="false"/>

		<!--- run setters --->
		<cfset setUserID(arguments.UserID) />
		<cfset setRole(arguments.Role) />
		<cfset setRoleCode(arguments.RoleCode) />
		<cfset setTimezone(arguments.Timezone) />
		<cfset setDefaultView(arguments.DefaultView) />
		<cfset setIsLoggedIn(arguments.isLoggedIn) />
		
		<cfreturn this />
 	</cffunction>

	<cffunction name="initWithXml" access="public" returntype="User" output="false">
		<cfargument name="userXml" type="string" default="" />
		<cfset var info = StructNew()/>
		<!--- run setters --->
		<cfset info.userID = arguments.userXml.XMLRoot.UserID.XmlText />
		<cfset info.RoleCode = arguments.userXml.XMLRoot.Role.XmlText />
		<cfset info.Role = getRoleMapping(arguments.userXml.XMLRoot.Role.XmlText) />
		
		<cfreturn init(argumentcollection=info) />
 	</cffunction>

	<!---
	ACCESSORS
	--->

	<cffunction name="getUserID" access="public" output="false" returntype="string">
		<cfreturn variables.instance.UserID />
	</cffunction>
	
	<cffunction name="setUserID" access="public" output="false" returntype="void">
		<cfargument name="userID" type="string" required="true" />
		<cfset variables.instance.userID = arguments.userID />
	</cffunction>
	
	<cffunction name="getRole" access="public" output="false" returntype="string">
		<cfreturn variables.instance.Role />
	</cffunction>
	
	<cffunction name="setRole" access="public" output="false" returntype="void">
		<cfargument name="Role" type="string" required="true" />
		<cfset variables.instance.Role = arguments.Role />
	</cffunction>

	<cffunction name="setRoleCode" access="public" output="false" returntype="void">
		<cfargument name="RoleCode" type="string" required="true" />
		<cfset variables.instance.RoleCode = arguments.RoleCode />
	</cffunction>
	
	<cffunction name="getRoleCode" access="public" output="false" returntype="string">
		<cfreturn variables.instance.RoleCode />
	</cffunction>
	
	<cffunction name="setTimezone" access="public" output="false" returntype="void">
		<cfargument name="Timezone" type="string" required="true" />
		<cfset variables.instance.Timezone = arguments.Timezone />
	</cffunction>
	
	<cffunction name="getTimezone" access="public" output="false" returntype="string">
		<cfreturn variables.instance.Timezone />
	</cffunction>
	
	<cffunction name="setDefaultView" access="public" output="false" returntype="void">
		<cfargument name="DefaultView" type="string" required="true" />
		<cfset variables.instance.DefaultView = arguments.DefaultView />
	</cffunction>
	
	<cffunction name="getDefaultView" access="public" output="false" returntype="string">
		<cfreturn variables.instance.DefaultView />
	</cffunction>
	
	<cffunction name="setIsLoggedIn" access="public" output="false" returntype="void">
		<cfargument name="IsLoggedIn" type="boolean" required="true" />
		<cfset variables.instance.IsLoggedIn = arguments.IsLoggedIn />
	</cffunction>
	
	<cffunction name="getIsLoggedIn" access="public" output="false" returntype="boolean">
		<cfreturn variables.instance.IsLoggedIn />
	</cffunction>
	

	<cffunction name="getRoleMapping" access="private" returntype="numeric">
		<cfargument name="code" type="string" required="true"/>
		<cfset var roleMapping = 0/>
		<cfswitch expression="#arguments.code#">
			<cfcase value="admin"><cfset roleMapping = 3/></cfcase>
			<cfcase value="dealer"><cfset roleMapping = 2/></cfcase>
			<cfcase value="mysource"><cfset roleMapping = 1/></cfcase>
			<cfdefaultcase><cfset roleMapping = 0/></cfdefaultcase>
		</cfswitch>
		<cfreturn roleMapping/>
	</cffunction>	

	<cffunction name="getMemento" access="public" returntype="struct" output="false">
		<cfreturn variables.instance />
	</cffunction>

</cfcomponent>